﻿<!doctype html>
<!--[if IE 7 ]>    <html lang="en-gb" class="isie ie7 oldie no-js"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en-gb" class="isie ie8 oldie no-js"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en-gb" class="isie ie9 no-js"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<html lang="en-gb" class="no-js">
<!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!--[if lt IE 9]>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <![endif]-->
    <title>优办公管理信息系统</title>
    {% load staticfiles %}
    <meta property="og:site_name" content="西安力啸网络科技有限公司" />
    <meta property="og:title" content="科技赋能未来" />
    <meta property="og:description" content=" 洞察 - 聚焦 - 创新" />
    <meta property="og:type" content="website" />
    <meta property="og:locale" content="zh_SG" />
    <meta name="twitter:card" content="summary" />
    <meta name="twitter:title" content="西安力啸网络科技有限公司" />
    <meta name="twitter:description" content="科技赋能未来" />
    <!--[if lt IE 9]>
            <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
    <!--[if lte IE 8]>
            <script type="text/javascript" src="http://explorercanvas.googlecode.com/svn/trunk/excanvas.js"></script>
        <![endif]-->
    
    <link rel="stylesheet" type="text/css" href="{% static 'lxoa/css/style_login.css' %}" />
    
</head>

<body style="background: url(/static/lxoa/images/background.jpg) no-repeat;">

    <div class="login">

        <div class="login-top">
            <div style="text-align:center;"><img src="/static/lxoa/images/logo_login.png" style="width:45%;" /></div>
            <div style="margin-top:10px;">
                <input type="text" value="" id="username" autofocus="autofocus" placeholder="请输入邮箱">
                <input type="password" value="" id="userpwd" autocomplete="new-password" placeholder="请输入密码">
            </div>

            <div class="forgot" id="error">

            </div>

            <div class="forgot">
                <!--<a href="#">忘记密码？</a>-->
                <!--<input type="checkbox" value="记住我">-->
                <div id="check_css3">
                    <span><input type="checkbox" class="input_check" id="check3"><label for="check3"></label></span><font style="position: absolute;margin-left: 6px;color: #757575;">记住我</font>
                </div>
            </div>
            <div class="forgot">
                <!--<a href="#">忘记密码？</a>-->
                <input type="button" onclick="loginbtn()" value="登录">
            </div>
        </div>

    </div>

    <footer class="footer">Copyright © 2018 西安力啸网络科技有限公司 版权所有 </footer>
</body>

<script src="{% static 'lxoa/js/jquery-1.10.2.min.js' %}"></script>

<script>
    function getCookie(name) {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
    function setCookie(c_name, value, expiredays) {
        var exdate = new Date()
        exdate.setDate(exdate.getDate() + expiredays)
        document.cookie = c_name + "=" + escape(value) +
            ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
    }
    $(document).ready(function () {
        var uname = getCookie('uname');
        if (uname && uname.length > 0) {
            $('#username').val(uname);
            $('#check3').attr("checked", "checked");
        }
    });
    function loginbtn() {
        var uname = $('#username');
        var upwd = $('#userpwd');

        if (uname.val().length < 1) {
            uname.attr('style', 'border:1px solid red;');
            uname.focus();
            return;
        }
        if (upwd.val().length < 1) {
            upwd.attr('style', 'border:1px solid red;');
            upwd.focus();
            return;
        }

        $.ajax({
            url: '/lxoa/userlogin/',
            type: 'POST',
            dataType: 'json',
            headers: { "X-CSRFToken": getCookie('csrftoken') },
            data: {
                username: uname.val(),
                userpwd: upwd.val()
            },
            success: function (data) {
                if (data && data.success == '1') {
                    if ($('#check3').is(":checked")) {
                        setCookie('uname', uname.val(), 7);
                    } else {
                        setCookie('uname', '', -7);
                    }
                    $('#error').html('登陆成功，正在跳转...').attr('style', 'color:green;');
                    location.href = '/lxoa/index';
                } else {
                    $('#error').html('登陆失败，用户名或密码错误。').attr('style', 'color:red;');
                }
            }
        })
    }
</script>

</html>
